window.onload = function(){
    var vm = new Vue({
        el:'#app',
        data:{
            start_block:'',
            end_block:'',
            error_start_block: false,
            error_end_block: false,
            url:'',
        },
        methods:{
            //检查数据
            check_start_block:function () {
                if(!this.start_block){
                    this.error_start_block = true;
                }else{
                    this.error_start_block = false;
                }
            },
            check_end_block:function () {
                if(!this.end_block){
                    this.error_end_block = true;
                }else{
                    this.error_end_block = false;
                }
            },
            // 生成url
            make_url:function(){
                this.url = 'http://localhost:6800/schedule.json?project=etherscan_spider&spider=blockinfo&start_block='+ this.start_block +'&end_block='+ this.end_block;
            },
            //提交
            on_submit:function () {
                this.check_start_block();
                this.check_end_block();


                if(this.error_start_block==false && this.error_end_block==false){
                    this.make_url();
                    axios({
                        method: 'post',
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                        },
                        url: this.url,
                        data: {
                            // project:'etherscan_spider',
                            // spider: 'blockinfo',
                            // start_block: this.start_block,
                            // end_block: this.end_block
                        }
                    })
                    .then(function (response) {
                        alert('爬虫已开启');
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                }

            }
        }
    })
};